package cn.com.v2.controller;

import cn.com.v2.model.ChartDataResponse;
import cn.com.v2.model.ProductData;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class DataController {

    @GetMapping
    public ResponseEntity<ChartDataResponse> getDynamicData() {
        Random random = new Random();

        List<String> dimensions = Arrays.asList("product", "data1", "data2");
        List<ProductData> source = new ArrayList<>();

        for (int i = 0; i < 7; i++) { // 随机生成一周的数据
            ProductData productData = new ProductData();
            String[] daysOfWeek = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
            productData.setProduct(daysOfWeek[i]);
            productData.setData1(random.nextInt(300)); // 随机生成data1值
            productData.setData2(random.nextInt(300)); // 随机生成data2值
            source.add(productData);
        }

        ChartDataResponse response = new ChartDataResponse();
        response.setDimensions(dimensions);
        response.setSource(source);

        return ResponseEntity.ok(response);
    }
}